package edu.sctu.renpingan.seekhomework;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Scanner;

/**
 * Created by Administrator on 2015/6/20.
 */

/**
 * 获取全班的学号及姓名
 */
public class GetInfoAndUtil {
    String allininfoaddress;
    String newininfoaddress;
    public GetInfoAndUtil(String allininfoaddress, String newininfoaddress){
     this.allininfoaddress = allininfoaddress;
     this.newininfoaddress = newininfoaddress;
    }


    /**
     * 将姓名与学号存入hashmap并对应起来
     * @return
     */
    public HashMap<String,String> getInfo(){
        File file = new File(allininfoaddress);
        String[] filename;
        filename = file.list();
        HashMap<String,String> map = new HashMap<String,String>();
        for (int i = 0; i < filename.length; i++) {
            String number = filename[i].substring(0, 10);
            String name = filename[i].substring(11, 14);
//            System.out.println(number+name);
            map.put(number,name);

        }
        return map;
    }


    /**
     * 将学号与临序号对应起来
     * @return
     */
    public List<String> getInfo1(){
        File file = new File(allininfoaddress);
        String[] filename;
        filename = file.list();
        List<String> list = new ArrayList<>();
        for (int i = 0; i < filename.length; i++) {
            String number = filename[i].substring(0, 10);

            list.add(number);

        }
        return list;
    }
    /**
     * 将新交的作业的学号与临序号对应起来
     * @return
     */
    public List<String> getInfo2(){
        File file = new File(newininfoaddress);
        String[] filename;
        filename = file.list();
        List<String> list = new ArrayList<>();
        for (int i = 0; i < filename.length; i++) {
            String number = filename[i].substring(0, 10);

            list.add(number);

        }
        return list;
    }

    /**
     * 比对谁未交作业
     */
    public void seeking(){
        System.out.println("未交作业:");
        for (int i = 0; i < getInfo1().size(); i++) {
            boolean key = getInfo2().contains(getInfo1().get(i));
            if (!key){
                String name = getInfo().get(getInfo1().get(i));
                    System.out.println(" " +name );

            }
        }
    }

}
